package it.polimi.traveldream;

import it.polimi.traveldream.entities.Hotel;
import it.polimi.traveldream.entities.Transport;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Session Bean implementation class GestioneShowTransport
 */
@Stateless
public class GestioneShowTransport implements GestioneShowTransportLocal {

	@PersistenceContext
    private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public GestioneShowTransport() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
    public List<TransportDTO> showTransport(){
    	Query q = em.createNamedQuery("Transport.findAll");
    	return convert(q.getResultList());
    }
    
    public List<TransportDTO> convert(List<Transport> list1){
    	List<TransportDTO>tmp=new ArrayList<TransportDTO>();
    	
    	for(Transport t: list1){
    		TransportDTO ttmp=new TransportDTO();
    		ttmp.setId(t.getId());
    		ttmp.setCittaArrivo(t.getCittaArrivo());
    		ttmp.setCittaPartenza(t.getCittaPartenza());
    		ttmp.setDataPartenza(t.getDataPartenza());
    		ttmp.setDurata(t.getDurata());
    		ttmp.setFrequenza(t.getFrequenza());
    		ttmp.setNome(t.getNome());
    		ttmp.setNPosti(t.getNPosti());
    		ttmp.setPrezzo(t.getPrezzo());
    		tmp.add(ttmp);
    	}
    	
    	return tmp;
    	
    }

}
